package com.example.xingxing.mobilesafe.view;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.xingxing.mobilesafe.R;

/**
 * Created by xingxing on 16/11/29.
 */

public class SettingItemView extends RelativeLayout {
    private static final String NAMESPACE = "http://schemas.android.com/apk/res-auto";
    private TextView titleView;
    private TextView descriptionView;
    private CheckBox checkBox;

    private String desc_on;
    private String desc_off;

    public SettingItemView(Context context) {
        super(context);
        initView();
    }

    public SettingItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();

        titleView.setText(attrs.getAttributeValue(NAMESPACE, "title"));
        desc_on = attrs.getAttributeValue(NAMESPACE, "desc_on");
        desc_off = attrs.getAttributeValue(NAMESPACE, "desc_off");
    }

    public SettingItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    private void initView() {
        View child = View.inflate(getContext(), R.layout.setting_item_view, null);

        titleView = (TextView) child.findViewById(R.id.si_title);
        descriptionView = (TextView) child.findViewById(R.id.si_desc);
        checkBox = (CheckBox) child.findViewById(R.id.si_check);

        this.addView(child);
    }

    public void setTitle(String title) {
        this.titleView.setText(title);
    }

    public void setDescription(String description) {
        this.descriptionView.setText(description);
    }

    public boolean isChecked() {
        return this.checkBox.isChecked();
    }
    public void setChecked(boolean checked) {
        this.checkBox.setChecked(checked);
        descriptionView.setText(checked ? desc_on : desc_off);
    }

}
